package com.cr.front.user.controller;

import com.cr.common.response.JsonResult;
import com.cr.front.user.pojo.dto.param.UserAddParam;
import com.cr.front.user.pojo.dto.param.UserUpdateParam;
import com.cr.front.user.pojo.vo.LoginResultVO;
import com.cr.front.user.pojo.vo.UserDetailVO;
import com.cr.front.user.service.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/users")
@Api(tags = "会员模块")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "新增会员")
    @PostMapping("register")
    public JsonResult add(@Validated @RequestBody UserAddParam userAddParam) {
        LoginResultVO loginResultVO = userService.insert(userAddParam);
        return JsonResult.success(loginResultVO);
    }

//    @ApiOperation(value = "查询会员详情")
//    @GetMapping("/{id}")
//    public JsonResult getDetail(@PathVariable("id") Long id) {
//        UserDetailVO userDetailVO = userService.selectById(id);
//        return JsonResult.success(userDetailVO);
//    }

    @ApiOperation(value = "查询当前登录会员详情")
    @GetMapping("/myinfo")
    public JsonResult getDetail() {
        UserDetailVO userDetailVO = userService.selectMyInfo();
        return JsonResult.success(userDetailVO);
    }

    @ApiOperation(value = "查询当前登录会员详情")
    @PostMapping("/update")
    public JsonResult updateUser(UserUpdateParam userUpdateParam) {
        userService.updateUser(userUpdateParam);
        return JsonResult.success();
    }

}

